package com.turtle.turtleformatter.autoconfigure;

import com.turtle.turtleformatter.formatter.DateFormatter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类
 */
@Configuration
@EnableConfigurationProperties(FormatterProperties.class)
@ConditionalOnClass(DateFormatter.class)
@ConditionalOnProperty(prefix = "format", name = "enabled", havingValue = "true")
public class FormatterAutoConfiguration {
    private final FormatterProperties formatterProperties;

    public FormatterAutoConfiguration(FormatterProperties formatterProperties) {
        this.formatterProperties = formatterProperties;
    }

    @Bean
    public DateFormatter dateFormatter(){
        return new DateFormatter(formatterProperties.getPattern());
    }
}
